package com.demo.io.talk1;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @author : YU.TAN
 * @date : 2021/11/15 15:38
 */
public class UdpServerDemo1 {
    public static void main(String[] args) throws Exception {
        //开放端口
        DatagramSocket socket=new DatagramSocket(9090);

        //接收数据
        byte[] bytes=new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(bytes, 0, bytes.length);

        socket.receive(datagramPacket);
        System.out.println(datagramPacket.getAddress());
        System.out.println(new String(datagramPacket.getData(),0,datagramPacket.getData().length));

        socket.close();
    }
}
